home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 3
/
Info_Mac_1994-01.iso
/
Development
/
General
/
SpriteWorld 1.0b3
/
Headers
/
Sprite.h
< prev
next >
Wrap
Text File
|
1993-06-05
|
7KB
|
170 lines
///--------------------------------------------------------------------------------------
// Sprite.h
//
// Created: Tuesday, October 27, 1992 at 10:10:06 PM
// By: Tony Myles
//
// Copyright: © 1991-93 Tony Myles, All rights reserved worldwide
//
// Description: constants, structures, and prototypes for sprites
///--------------------------------------------------------------------------------------
#ifndef __SPRITE__
#define __SPRITE__
#ifndef __TIMER__
#include <Timer.h>
#endif
#ifndef __FRAME__
#include "Frame.h"
#endif
#ifndef SW_PASCAL
#define SW_PASCAL
#endif
///--------------------------------------------------------------------------------------
// time task data structure
///--------------------------------------------------------------------------------------
typedef struct TimeTaskRec TimeTaskRec;
typedef TimeTaskRec *TimeTaskPtr, **TimeTaskHdl;
struct TimeTaskRec
{
TMTask timeTask;
Boolean hasTaskFired;
};
///--------------------------------------------------------------------------------------
// sprite type definitions
///--------------------------------------------------------------------------------------
typedef struct SpriteRec SpriteRec;
typedef SpriteRec *SpritePtr, **SpriteHdl;
#ifdef __cplusplus
extern "C" {
#endif
typedef SW_PASCAL void (*DrawProcPtr)(FramePtr srcFrameP, FramePtr dstFrameP, Rect *srcRect, Rect *dstRect);
typedef SW_PASCAL void (*MaskDrawProcPtr)(FramePtr srcFrameP, FramePtr dstFrameP, Rect *srcRect, Rect *dstRect, RgnHandle maskRgn);
typedef SW_PASCAL void (*FrameProcPtr)(SpritePtr srcSpriteP, FramePtr curFrameP, long *frameIndex);
typedef SW_PASCAL void (*MoveProcPtr)(SpritePtr srcSpriteP, Point *spriteLoc);
typedef SW_PASCAL void (*CollideProcPtr)(SpritePtr srcSpriteP, SpritePtr dstSpriteP, Rect* sectRect);
#ifdef __cplusplus
};
#endif
///--------------------------------------------------------------------------------------
// sprite data structure
///--------------------------------------------------------------------------------------
struct SpriteRec
{
SpritePtr nextSpriteP; // next sprite
SpritePtr prevSpriteP; // previous sprite
// drawing fields
Boolean isVisible; // draw the sprite?
Boolean needsToBeDrawn; // sprite has changed, needs to be drawn
Boolean needsToBeErased; // sprite needs to be erased onscreen
char pad1;
Rect destFrameRect; // frame destination rectangle
Rect oldFrameRect; // last frame destination rectangle
Rect deltaFrameRect; // union of the sprite’s lastRect and curRect
RgnHandle screenMaskRgn; // mask region for drawing sprite to screen
DrawProcPtr frameDrawProc; // callback to draw sprite
// frame fields
TimeTaskRec frameTimeTask; // frame advance time task
FramePtr *frameArray; // array of frames
FramePtr curFrameP; // current frame
long numFrames; // number of frames
long maxFrames; // maximum number of frames
long frameTimeInterval; // time interval to advance frame
long frameAdvance; // amount the adjust frame index
long curFrameIndex; // current frame index
long firstFrameIndex; // first frame to advance
long lastFrameIndex; // last frame to advance
FrameProcPtr frameChangeProc; // callback to change frames
// movement fields
TimeTaskRec moveTimeTask; // movement time task
long moveTimeInterval; // time interval to move sprite
short horizMoveDelta; // horizontal movement delta
short vertMoveDelta; // vertical movement delta
Rect moveBoundsRect; // bounds of the sprite’s movement
MoveProcPtr spriteMoveProc; // callback to handle movement
// collision detection fields
Rect collideRect; // collision detection rectangle (not used currently)
CollideProcPtr spriteCollideProc; // callback to handle collisions
long userData; // reserved for user
};
///--------------------------------------------------------------------------------------
// sprite function prototypes
///--------------------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
#endif
SW_PASCAL OSErr SWCreateSprite(SpritePtr* newSpriteP, void* spriteStorageP, short maxFrames);
SW_PASCAL OSErr SWCreateSpriteFromCIconResource(SpritePtr* newSpriteP, void* spriteStorageP,
short cIconID, short maxFrames, MaskType maskType);
SW_PASCAL OSErr SWCreateSpriteFromPictResource(SpritePtr* newSpriteP, void* spriteStorageP,
short pictResID, short maskResID, short maxFrames, MaskType maskType);
SW_PASCAL OSErr SWCloneSprite(SpritePtr cloneSpriteP, SpritePtr *newSpriteP, void* spriteStorageP);
SW_PASCAL void SWDisposeSprite(SpritePtr oldSpriteP, Boolean disposeFrames);
SW_PASCAL void SWCloseSprite(SpritePtr deadSpriteP, Boolean disposeFrames);
SW_PASCAL void SWLockSprite(SpritePtr srcSpriteP);
SW_PASCAL void SWUnlockSprite(SpritePtr srcSpriteP);
SW_PASCAL void SWSetSpriteDrawProc(SpritePtr srcSpriteP, DrawProcPtr drawProc);
SW_PASCAL OSErr SWAddFrame(SpritePtr srcSpriteP, FramePtr newFrameP);
SW_PASCAL void SWRemoveFrame(SpritePtr srcSpriteP, FramePtr oldFrameP);
SW_PASCAL void SWSetCurrentFrame(SpritePtr srcSpriteP, FramePtr curFrameP);
SW_PASCAL void SWSetCurrentFrameIndex(SpritePtr srcSpriteP, short frameIndex);
SW_PASCAL void SWSetSpriteFrameAdvance(SpritePtr srcSpriteP, short frameAdvance);
SW_PASCAL void SWSetSpriteFrameRange(SpritePtr srcSpriteP, short firstFrameIndex, short lastFrameIndex);
SW_PASCAL void SWSetSpriteFrameTime(SpritePtr srcSpriteP, long timeInterval);
SW_PASCAL void SWSetSpriteFrameProc(SpritePtr srcSpriteP, FrameProcPtr frameProc);
SW_PASCAL void SWMoveSprite(SpritePtr srcSpriteP, short horizLoc, short vertLoc);
SW_PASCAL void SWOffsetSprite(SpritePtr srcSpriteP, short horizDelta, short vertDelta);
SW_PASCAL void SWSetSpriteLocation(SpritePtr srcSpriteP, short horizLoc, short vertLoc);
SW_PASCAL void SWSetSpriteMoveBounds(SpritePtr srcSpriteP, Rect* moveBoundsRect);
SW_PASCAL void SWSetSpriteMoveDelta(SpritePtr srcSpriteP, short horizDelta, short vertDelta);
SW_PASCAL void SWSetSpriteMoveTime(SpritePtr srcSpriteP, long timeInterval);
SW_PASCAL void SWSetSpriteMoveProc(SpritePtr srcSpriteP, MoveProcPtr moveProc);
SW_PASCAL void SWBounceSpriteMoveProc(SpritePtr srcSpriteP, Point* spritePoint);
SW_PASCAL void SWWrapSpriteMoveProc(SpritePtr srcSpriteP, Point* spritePoint);
SW_PASCAL void SWSetSpriteCollideProc(SpritePtr srcSpriteP, CollideProcPtr collideProc);
SW_PASCAL void SWSetSpriteVisible(SpritePtr srcSpriteP, Boolean isVisible);
SW_PASCAL Boolean SWIsSpriteInRect(SpritePtr srcSpriteP, Rect* testRect);
SW_PASCAL void SWStdDrawProc(FramePtr srcFrameP, FramePtr dstFrameP, Rect* srcRect, Rect* dstRect);
SW_PASCAL void SWStdMaskDrawProc(FramePtr srcFrameP, FramePtr dstFrameP,
Rect* srcRect, Rect* dstRect, RgnHandle maskRgn);
pascal void SWTimeTask(void);
SW_PASCAL Boolean SWIsTaskPrimed(TMTask* tmTaskP);
#ifdef __cplusplus
};
#endif
#endif /* __SPRITE__ */